package cn.com.server.controller.orderListManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;

import cn.com.server.common.AjaxCodeUtil;
import cn.com.server.common.AjaxObject;
import cn.com.server.common.util.RegExpValidatorUtils;
import cn.com.server.entity.Storehouse;
import cn.com.server.service.StorehouseService;
import cn.com.server.extend.model.StorehouseModel;

@Controller
@RequestMapping("/storehouse")
public class StorehouseController {
	
	@Autowired
	private StorehouseService storehouseService;
	
	@RequestMapping("/storehouse")
	public String storehouse(HttpServletRequest request, HttpServletResponse response) {
		return "/productListManager/storehouse";
	}

	@RequestMapping("/getStorehouseList")
	@ResponseBody
	public AjaxObject getStorehouseList(StorehouseModel model,HttpServletRequest request, HttpServletResponse response,HttpSession session) {
		Page<Storehouse> pageData = storehouseService.selectStorehouse(model);
		AjaxObject ajaxObject = AjaxCodeUtil.getAjaxObject("success");
		ajaxObject.setData(pageData);
		return ajaxObject;
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public AjaxObject save(Storehouse entity,HttpServletRequest request, HttpServletResponse response,HttpSession session) {
		if(entity.getId()!=null) {//修改
			storehouseService.update(entity);
		}else {//新增
			storehouseService.insert(entity);
		}
		AjaxObject ajaxObject = AjaxCodeUtil.getAjaxObject("success");
		return ajaxObject;
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public AjaxObject delete(String ids,HttpServletRequest request, HttpServletResponse response,HttpSession session) {
		if(RegExpValidatorUtils.isNumberIds(ids)) {//修改
			storehouseService.updateDeleteIds(ids);
			AjaxObject ajaxObject = AjaxCodeUtil.getAjaxObject("success");
			return ajaxObject;
		}else {
			AjaxObject ajaxObject = AjaxCodeUtil.getAjaxObject("fail");
			return ajaxObject;
		}
	}
}
